import React, { useState, useEffect } from 'react';
import { useHistory, useLocation } from "react-router-dom"
import {
    Form,
    Input,
    Button,
    Select,
    DatePicker,
    notification
} from 'antd';
import service from '../../../../utils/service';
import 'dayjs/locale/zh-cn';


export default function Index() {
    const [form] = Form.useForm();
    const history = useHistory();
    const location = useLocation();
    let data2: any;
    useEffect(() => {
        const mylocation: any = location.state;
        // console.log("mylocation.data", mylocation.data);
        console.log({ ...mylocation.data });
        data2 = { ...mylocation.data }

        // form.setFieldsValue(props.location.state.id)
        form.setFieldsValue(mylocation.data)

    }, [])
    const onFinish = (values: any) => {
        values = { ...data2, ...values }
        console.log('Success:', values);
        service({
            url: "/security/" + values.id,
            method: "patch",
            data: values
        }).then(res => {
            if (res.status === 200) {
                history.push("/Main/SecurityStaff")

            }
            console.log("res.data", res.data)
        })
    };
    const toReset = () => {
        console.log("111");
        let data = { ...data2 };
        for (var key in data) {
            data[key] = ''
        }
        form.setFieldsValue(data)
    }

    return (
        <div>
            <h1>编辑</h1>
            <>
                <Form
                    form={form}
                    labelCol={{ span: 4 }}
                    wrapperCol={{ span: 14 }}
                    layout="horizontal"
                    onFinish={onFinish}
                    style={{ display: "flex", maxWidth: 600 }}
                >
                    <div>
                        <Form.Item
                            label="id"
                            name="id"
                            hidden>
                        </Form.Item>

                        <Form.Item
                            label="key"
                            name="key"
                            hidden>
                        </Form.Item>
                        <Form.Item
                            label="学校名称"
                            name="schoolName">
                            <Input />
                        </Form.Item>

                        <Form.Item
                            name="staffName"
                            label="保安姓名">
                            <Input />
                        </Form.Item>
                        <Form.Item
                            name="phone"
                            label="联系电话">
                            <Input />
                        </Form.Item>
                        <Form.Item
                            initialValue="性别"
                            name="sex"
                            label="性别">
                            <Select defaultValue="性别">
                                <Select.Option value="全部">全部</Select.Option>
                                <Select.Option value="男">男</Select.Option>
                                <Select.Option value="女">女</Select.Option>
                            </Select>
                        </Form.Item>
                        <Form.Item
                            initialValue="学历"
                            name="educationalBackground"
                            label="学历">
                            <Select defaultValue="学历">
                                <Select.Option value="无学历">无学历</Select.Option>
                                <Select.Option value="小学">小学</Select.Option>
                                <Select.Option value="初中">初中</Select.Option>
                                <Select.Option value="中专">中专</Select.Option>
                                <Select.Option value="高中">高中</Select.Option>
                                <Select.Option value="专科">专科</Select.Option>
                                <Select.Option value="本科">本科</Select.Option>
                            </Select>
                        </Form.Item>
                        {/* <Form.Item
                            name="date"
                            label="聘用日期"
                            hidden
                        >

                            <DatePicker />
                        </Form.Item> */}
                        <Form.Item
                            initialValue="聘用性质"
                            name="nature"
                            label="聘用性质">
                            <Select defaultValue="聘用性质">
                                <Select.Option value="全部">全部</Select.Option>
                                <Select.Option value="自聘">自聘</Select.Option>
                                <Select.Option value="代理">代理</Select.Option>
                                <Select.Option value="委派">委派</Select.Option>
                            </Select>
                        </Form.Item>

                        <Form.Item /* wrapperCol={{ offset: 8, span: 16 }} */ style={{ display: "flex" }}>
                            <Button type="primary" htmlType="submit">
                                确定
                            </Button>

                        </Form.Item>
                        <Button onClick={toReset}>重置</Button>
                    </div>
                    <div>
                        <Form.Item
                            name="staffAge"
                            label="年龄">
                            <Input />
                        </Form.Item>
                        <Form.Item
                            name="staffNum"
                            label="保安证编号">
                            <Input />
                        </Form.Item>
                        <Form.Item
                            name="adress"
                            label="现居住地址">
                            <Input />
                        </Form.Item>
                        <Form.Item
                            name="nation"
                            label="民族">
                            <Input />
                        </Form.Item>
                        <Form.Item
                            initialValue="政治面貌"
                            name="face"
                            label="政治面貌">
                            <Select defaultValue="政治面貌">
                                <Select.Option value="群众">群众</Select.Option>
                                <Select.Option value="共青团员">共青团员</Select.Option>
                                <Select.Option value="中共预备党员">中共预备党员</Select.Option>
                                <Select.Option value="中共党员">中共党员</Select.Option>
                            </Select>
                        </Form.Item>
                        <Form.Item
                            name="salary"
                            label="应发月薪（元）">
                            <Input />
                        </Form.Item>
                    </div>
                </Form>
            </>



        </div>

    )
}
